<?php 
date_default_timezone_set("PRC"); 
//****************************************	//MD5密钥要跟订单提交页相同，如Send.asp里的 key = "test" ,修改""号内 test 为您的密钥
$db = include('../Application/Common/Conf/config.php');												//如果您还没有设置MD5密钥请登陆我们为您提供商户后台，地址：https://merchant3.chinabank.com.cn/
								//登陆后在上面的导航栏里可能找到“B2C”，在二级导航栏里有“MD5密钥设置”
										//建议您设置一个16位以上的密钥或更高，密钥最多64位，但设置16位已经足够了
//****************************************
$key= $db['bankmd5'];
$v_oid     =trim($_POST['v_oid']);     
$v_pmode   =trim($_POST['v_pmode']);      
$v_pstatus =trim($_POST['v_pstatus']);   
$v_pstring =trim($_POST['v_pstring']);       
$v_amount  =trim($_POST['v_amount']); 
$v_moneytype =trim($_POST['v_moneytype']);       
$remark1   =trim($_POST['remark1']);     
$remark2   =trim($_POST['remark2']);     
$v_md5str  =trim($_POST['v_md5str']);     
/**
 * 重新计算md5的值
 */
                        
$md5string=strtoupper(md5($v_oid.$v_pstatus.$v_amount.$v_moneytype.$key)); //拼凑加密串
if ($v_md5str==$md5string)
{
	
   if($v_pstatus=="20")
	{										
				$host =  $db['DB_HOST'];
				$port =  $db['DB_PORT'];
				$dbname =  $db['DB_NAME'];
				$user =  $db['DB_USER'];
				$psw =  $db['DB_PWD'];
				$dbconn = pg_connect("host=$host port=$port dbname=$dbname user=$user password=$psw");			
				if($dbconn){
						/************更新支付状态********************/
						$sql = "update tbusercashflow set nstate=1 where corderid='$v_oid';";
						$check = pg_query($dbconn,$sql);	
						$row = pg_affected_rows($check);
						if($row){
							/**************添加流水金币****************************/
							$sql = "select nuserid,nmoney from tbusercashflow where corderid='$v_oid';";
							$infor = pg_query($dbconn,$sql);
							$infor = pg_fetch_assoc($infor);
							$nuserid = $infor['nuserid'];
							$nmoney = $infor['nmoney'];						
							$balanceSql = "select nmoney from tbuseraccount where nuserid=$nuserid"; //获取用户金币
							$balance = pg_query($dbconn,$balanceSql);
							$nbalance = pg_fetch_array($balance);			
							$nbalance = $nbalance['nmoney'];
							$total = $nbalance+$nmoney;			
							$addsql = "INSERT INTO tbusermoneyflow (nuserid,ntype,nmoney,nbalance,cdesc) VALUES ($nuserid,1,$nmoney,$total,'网银充值');";				
							pg_query($dbconn,$addsql);
		
						}
					}
		
	   //支付成功
		//商户系统的逻辑处理（例如判断金额，判断支付状态(20成功,30失败),更新订单状态等等）......
		
	}
  echo "ok";
	
}else{
	echo "error";
}
?>